package com.cisco.pso;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.cisco.pso.FileItem;

public class ReviseReader {

	protected Map<String, ReviseItem> map = new HashMap<String, ReviseItem>();

	public ReviseReader(Reader reader) {

		BufferedReader br = new BufferedReader(reader);

		Set<String> keys = new HashSet<String>();

		while (true) {

			try {
				String line = br.readLine();
				if (line == null || line.trim().isEmpty() || line.startsWith("#"))
					break;

				if (keys.add(line) == false)
					throw new RuntimeException("duplicate file name");

				ReviseItem item = new ReviseItem(line);

				if (item.isEnabled())
					map.put(item.getPsoFileName(), item);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}

		}

	}

	protected String getShortName(String fullName) {
		int index = fullName.lastIndexOf('/');
		return fullName.substring(index + 1);
	}

	public Map<String, ReviseItem> getMap() {
		return map;
	}

	public void setMap(Map<String, ReviseItem> map) {
		this.map = map;
	}

}
